<template>
  <div class="page-container">
    <div class="background-decoration"></div>
    <div class="content-wrapper">
      <div class="brand-section">
        <div class="logo">
          <Icon name="material-symbols:lock-person" class="h-10 w-10" />
          <span class="brand-name">深度求索</span>
        </div>
        <div class="brand-tagline">安全、简单、快速的身份验证</div>
      </div>
      <div class="auth-card">
        <div class="modal-header">
          <div class="tech-decoration"></div>
          <h2 class="modal-title">创建账户</h2>
          <p class="modal-subtitle">填写以下信息完成注册</p>
        </div>
        <form class="auth-form" @submit.prevent="handleSubmit">
          <!-- 表单内容保持不变 -->
          <div class="form-group">
            <label for="username" class="form-label">用户名</label>
            <div class="input-wrapper">
              <Icon name="material-symbols:person" class="input-icon h-5 w-5" />
              <input
                  id="username"
                  type="text"
                  v-model="username"
                  placeholder="请创建用户名"
                  class="form-input"
                  :class="{ error: usernameError }"
              >
            </div>
            <p class="error-message" v-if="usernameError">{{ usernameError }}</p>
          </div>
          <div class="form-group">
            <label for="email" class="form-label">邮箱</label>
            <div class="input-wrapper">
              <Icon name="material-symbols:alternate-email" class="input-icon h-5 w-5" />
              <input
                  id="email"
                  type="email"
                  v-model="email"
                  placeholder="请输入邮箱地址"
                  class="form-input"
                  :class="{ error: emailError }"
                  @input="validateEmail"
              >
            </div>
            <p class="error-message" v-if="emailError">{{ emailError }}</p>
          </div>
          <div class="form-group">
            <label for="verificationCode" class="form-label">验证码</label>
            <div class="input-wrapper with-button">
              <Icon name="material-symbols:verified" class="input-icon h-5 w-5 yzhm-icon" />
              <input
                  id="verificationCode"
                  type="text"
                  v-model="verificationCode"
                  placeholder="请输入验证码"
                  class="form-input"
                  :class="{ error: verificationCodeError }"
                  maxlength="6"
              >
              <button
                  type="button"
                  class="send-code-btn"
                  @click="sendVerificationCode"
                  :disabled="!canSendCode || isSendingCode"
              >
                <span v-if="!isSendingCode && !countdownActive">发送验证码</span>
                <span v-if="isSendingCode">发送中...</span>
                <span v-if="countdownActive">{{ countdown }}s 后重发</span>
              </button>
            </div>
            <p class="error-message" v-if="verificationCodeError">{{ verificationCodeError }}</p>
          </div>
          <div class="form-group">
            <label for="password" class="form-label">密码</label>
            <div class="input-wrapper">
              <Icon name="material-symbols:lock" class="input-icon h-5 w-5" />
              <input
                  id="password"
                  :type="showPassword ? 'text' : 'password'"
                  v-model="password"
                  placeholder="请创建密码（至少8个字符）"
                  class="form-input"
                  :class="{ error: passwordError }"
                  @input="checkPasswordStrength"
              >
              <button
                  type="button"
                  class="toggle-password"
                  @click="showPassword = !showPassword"
                  :title="showPassword ? '隐藏密码' : '显示密码'"
                  aria-label="切换密码可见性"
              >
                <Icon :name="showPassword ? 'material-symbols:visibility' : 'material-symbols:visibility-off'" class="h-5 w-5" />
              </button>
            </div>
            <div class="password-strength" v-if="password.length > 0">
              <div class="strength-bars">
                <div
                    class="strength-bar"
                    :class="getStrengthClass(1)"
                ></div>
                <div
                    class="strength-bar"
                    :class="getStrengthClass(2)"
                ></div>
                <div
                    class="strength-bar"
                    :class="getStrengthClass(3)"
                ></div>
              </div>
              <div class="strength-text">
                {{ getStrengthText() }}
              </div>
              <div class="strength-hint" v-if="passwordStrength < 3">
                {{ getStrengthHint() }}
              </div>
            </div>

            <p class="error-message" v-if="passwordError">{{ passwordError }}</p>
          </div>
          <div class="form-group">
            <label for="confirmPassword" class="form-label">确认密码</label>
            <div class="input-wrapper">
              <Icon name="material-symbols:lock" class="input-icon h-5 w-5" />
              <input
                  id="confirmPassword"
                  :type="showPassword ? 'text' : 'password'"
                  v-model="confirmPassword"
                  placeholder="请再次输入密码"
                  class="form-input"
                  :class="{ error: confirmPasswordError }"
              >
            </div>
            <p class="error-message" v-if="confirmPasswordError">{{ confirmPasswordError }}</p>
          </div>
          <div class="terms-agreement form-group">
            <label class="terms-label">
              <input
                  type="checkbox"
                  v-model="agreeTerms"
                  class="terms-checkbox"
                  :class="{ error: termsError }"
              >
              <span class="terms-text">
                我已阅读并同意
                <NuxtLink href="#" class="link primary" @click.prevent="handleShowTerms">服务条款</NuxtLink>
                和
                <NuxtLink href="#" class="link primary" @click.prevent="handleShowPrivacy">隐私政策</NuxtLink>
              </span>
            </label>
            <p class="error-message" v-if="termsError">{{ termsError }}</p>
          </div>
          <button
              type="submit"
              class="submit-btn"
              :disabled="isSubmitting"
          >
          <span v-if="!isSubmitting">
              <Icon name="material-symbols:how-to-reg" class="h-4 w-4 mr-2" />
              注册
            </span>
            <span v-if="isSubmitting" class="loading">
              <span class="dot"></span>
              <span class="dot"></span>
              <span class="dot"></span>
            </span>
          </button>
        </form>
        <div class="login-prompt">
          已有账户?
          <NuxtLink to="/" class="link primary">
            立即登录
          </NuxtLink>
        </div>
        <div class="google-login-section">
          <div class="divider">
            <span>或使用谷歌账号快速注册</span>
          </div>
          <button class="google-login-btn" title="使用谷歌账号注册" aria-label="谷歌注册" @click="handleGoogleRegister">
            <Icon name="fa-brands:google" class="google-icon h-5 w-5 mr-2"/>
            <span>
              使用谷歌注册
            </span>
          </button>
        </div>
      </div>
      <footer class="footer">
        <MainFooter />
      </footer>
    </div>
  </div>

  <!-- 添加Toast提示组件 -->
  <div
      class="toast-notification"
      :class="{ 'visible': showToast }"
  >
    <Icon name="material-symbols:check-circle" class="toast-icon" v-if="toastType === 'success'" />
    <Icon name="material-symbols:error" class="toast-icon" v-if="toastType === 'error'" />
    <span class="toast-message">{{ toastMessage }}</span>
  </div>
</template>

<script setup lang="ts">
import MainFooter from '@/components/Footer/MainFooter.vue'
useHead({
  title: '注册 - 深度关联',
  meta: [
    {
      name: 'description',
      content: '注册金融简讯，加入深度关联的金融社区，获取金融资讯、分析和工具。'
    }
  ]
})

// 状态管理
const showPassword = ref<boolean>(false);
const isSubmitting = ref<boolean>(false);
const agreeTerms = ref<boolean>(false);
const passwordStrength = ref<number>(0); // 0-3，3为最强
const countdown = ref<number>(60);
const countdownActive = ref<boolean>(false);
const isSendingCode = ref<boolean>(false);

// 添加Toast相关状态
const showToast = ref<boolean>(false);
const toastMessage = ref<string>('');
const toastType = ref<'success' | 'error'>('success');

// 表单数据
const username = ref<string>('');
const email = ref<string>('');
const verificationCode = ref<string>('');
const password = ref<string>('');
const confirmPassword = ref<string>('');
const generatedCode = ref<string>(''); // 存储生成的验证码，实际应用中由后端生成

// 错误信息
const usernameError = ref<string>('');
const emailError = ref<string>('');
const verificationCodeError = ref<string>('');
const passwordError = ref<string>('');
const confirmPasswordError = ref<string>('');
const termsError = ref<string>('');

// 倒计时计时器
let countdownTimer: NodeJS.Timeout | null = null;
// Toast计时器
let toastTimer: NodeJS.Timeout | null = null;

// 页面加载时的动画效果
onMounted(() => {
  document.body.classList.add('auth-page');

  return () => {
    document.body.classList.remove('auth-page');
  };
});

// 组件卸载时清除计时器
onUnmounted(() => {
  if (countdownTimer) {
    clearInterval(countdownTimer);
  }
  if (toastTimer) {
    clearTimeout(toastTimer);
  }
});

// 显示提示信息的方法
const showToastMessage = (message: string, type: 'success' | 'error' = 'success', duration = 3000) => {
  // 清除之前的计时器
  if (toastTimer) {
    clearTimeout(toastTimer);
  }

  toastMessage.value = message;
  toastType.value = type;
  showToast.value = true;

  // 一段时间后自动隐藏
  toastTimer = setTimeout(() => {
    showToast.value = false;
  }, duration);
};

// 检查是否可以发送验证码
const canSendCode = computed(() => {
  return email.value.trim() !== '' && isValidEmail(email.value.trim()) && !countdownActive.value && !isSendingCode.value;
});

// 发送验证码
const sendVerificationCode = async () => {
  if (!validateEmail()) {
    return;
  }

  isSendingCode.value = true;
  verificationCodeError.value = '';

  try {
    // 模拟API请求
    await new Promise(resolve => setTimeout(resolve, 1000));

    // 生成6位随机验证码（实际应用中由后端生成并发送到邮箱）
    generatedCode.value = Math.floor(100000 + Math.random() * 900000).toString();
    console.log('验证码已发送到邮箱:', generatedCode.value);

    // 显示成功提示
    showToastMessage(`验证码已发送至 ${email.value}，请查收`);

    // 开始倒计时
    startCountdown();
  } catch (error) {
    console.error('发送验证码失败', error);
    verificationCodeError.value = '发送验证码失败，请稍后重试';
    // 显示错误提示
    showToastMessage('发送验证码失败，请稍后重试', 'error');
  } finally {
    isSendingCode.value = false;
  }
};

// 开始倒计时
const startCountdown = () => {
  countdownActive.value = true;
  countdown.value = 60;

  if (countdownTimer) {
    clearInterval(countdownTimer);
  }

  countdownTimer = setInterval(() => {
    countdown.value--;
    if (countdown.value <= 0) {
      countdownActive.value = false;
      if (countdownTimer) {
        clearInterval(countdownTimer);
        countdownTimer = null;
      }
    }
  }, 1000);
};

// 检查密码强度
const checkPasswordStrength = () => {
  let strength = 0;
  const pass = password.value;

  // 基础长度检查
  if (pass.length < 8) {
    passwordStrength.value = 0;
    return;
  }

  // 检查字符类型
  const hasLower = /[a-z]/.test(pass);
  const hasUpper = /[A-Z]/.test(pass);
  const hasNumber = /[0-9]/.test(pass);
  const hasSpecial = /[^A-Za-z0-9]/.test(pass);

  // 计算字符类型数量
  const charTypes = [hasLower, hasUpper, hasNumber, hasSpecial].filter(Boolean).length;

  // 弱：至少8个字符，且只有1-2种字符类型
  // 中：至少8个字符，且有3种字符类型
  // 强：至少8个字符，且包含所有4种字符类型
  if (charTypes >= 4) {
    strength = 3; // 强
  } else if (charTypes === 3) {
    strength = 2; // 中
  } else if (charTypes >= 1) {
    strength = 1; // 弱
  }

  passwordStrength.value = strength;
};

// 获取密码强度对应的样式类
const getStrengthClass = (level: number) => {
  if (passwordStrength.value >= level) {
    if (level === 1) return 'weak';
    if (level === 2) return 'medium';
    if (level === 3) return 'strong';
  }
  return 'empty';
};

// 获取密码强度文本描述
const getStrengthText = () => {
  if (password.value.length < 8) {
    return '密码长度不足';
  }

  switch (passwordStrength.value) {
    case 0: return '未输入';
    case 1: return '弱';
    case 2: return '中';
    case 3: return '强';
    default: return '';
  }
};

// 获取密码强度提升提示
const getStrengthHint = () => {
  if (password.value.length < 8) {
    return '密码至少需要8个字符';
  }

  const hasLower = /[a-z]/.test(password.value);
  const hasUpper = /[A-Z]/.test(password.value);
  const hasNumber = /[0-9]/.test(password.value);
  const hasSpecial = /[^A-Za-z0-9]/.test(password.value);

  if (passwordStrength.value === 1) {
    if (!hasUpper) return '添加大写字母可以提高密码强度';
    if (!hasNumber) return '添加数字可以提高密码强度';
    if (!hasSpecial) return '添加特殊符号可以提高密码强度';
    return '增加字符类型可以提高密码强度';
  } else if (passwordStrength.value === 2) {
    if (!hasUpper) return '添加大写字母可以使密码强度达到强';
    if (!hasNumber) return '添加数字可以使密码强度达到强';
    if (!hasSpecial) return '添加特殊符号可以使密码强度达到强';
    if (!hasLower) return '添加小写字母可以使密码强度达到强';
    return '增加一种字符类型可以使密码强度达到强';
  }

  return '';
};

// 处理谷歌注册
const handleGoogleRegister = () => {
  console.log('谷歌注册');
};

// 显示服务条款
const handleShowTerms = () => {
  navigateTo('#');
};

// 显示隐私政策
const handleShowPrivacy = () => {
  navigateTo('#');
};

// 重置表单
const resetForm = () => {
  username.value = '';
  email.value = '';
  verificationCode.value = '';
  password.value = '';
  confirmPassword.value = '';
  agreeTerms.value = false;
  passwordStrength.value = 0;

  usernameError.value = '';
  emailError.value = '';
  verificationCodeError.value = '';
  passwordError.value = '';
  confirmPasswordError.value = '';
  termsError.value = '';

  isSubmitting.value = false;
  showPassword.value = false;
};

// 验证邮箱格式
const validateEmail = () => {
  if (email.value.trim() && !isValidEmail(email.value.trim())) {
    emailError.value = '请输入有效的邮箱地址';
    return false;
  } else {
    emailError.value = '';
    return true;
  }
};

// 邮箱格式验证
const isValidEmail = (email: string): boolean => {
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return emailRegex.test(email);
};

// 表单验证
const validateForm = (): boolean => {
  let isValid = true;

  // 重置错误信息
  usernameError.value = '';
  emailError.value = '';
  verificationCodeError.value = '';
  passwordError.value = '';
  confirmPasswordError.value = '';
  termsError.value = '';

  // 验证用户名
  if (!username.value.trim()) {
    usernameError.value = '请输入用户名';
    isValid = false;
  } else if (username.value.length < 3) {
    usernameError.value = '用户名至少3个字符';
    isValid = false;
  } else if (username.value.length > 20) {
    usernameError.value = '用户名不能超过20个字符';
    isValid = false;
  }

  // 验证邮箱
  if (!email.value.trim()) {
    emailError.value = '请输入邮箱地址';
    isValid = false;
  } else if (!isValidEmail(email.value.trim())) {
    emailError.value = '请输入有效的邮箱地址';
    isValid = false;
  }

  // 验证验证码
  if (!verificationCode.value.trim()) {
    verificationCodeError.value = '请输入验证码';
    isValid = false;
  } else if (verificationCode.value.length !== 6) {
    verificationCodeError.value = '验证码为6位数字';
    isValid = false;
  } else if (verificationCode.value !== generatedCode.value) {
    verificationCodeError.value = '验证码不正确';
    // 显示错误提示
    showToastMessage('验证码不正确，请重新输入', 'error');
    isValid = false;
  }

  // 验证密码
  if (!password.value) {
    passwordError.value = '请输入密码';
    isValid = false;
  } else if (password.value.length < 8) {
    passwordError.value = '密码至少8个字符';
    isValid = false;
  } else if (!/(?=.*[A-Za-z])(?=.*\d)/.test(password.value)) {
    passwordError.value = '密码必须包含字母和数字';
    isValid = false;
  } else if (passwordStrength.value < 1) {
    passwordError.value = '密码不符合基本安全要求';
    isValid = false;
  }

  // 验证确认密码
  if (!confirmPassword.value) {
    confirmPasswordError.value = '请再次输入密码';
    isValid = false;
  } else if (confirmPassword.value !== password.value) {
    confirmPasswordError.value = '两次输入的密码不一致';
    isValid = false;
  }

  // 验证同意条款
  if (!agreeTerms.value) {
    termsError.value = '请阅读并同意服务条款和隐私政策';
    isValid = false;
  }

  return isValid;
};

// 处理表单提交
const handleSubmit = async () => {
  if (!validateForm()) {
    // 表单验证失败时，滚动到第一个错误字段
    const firstError = document.querySelector('.form-input.error');
    if (firstError) {
      firstError.scrollIntoView({ behavior: 'smooth', block: 'center' });
    }
    return;
  }

  isSubmitting.value = true;

  try {
    // 模拟API请求延迟
    await new Promise(resolve => setTimeout(resolve, 1800));

    // 模拟注册成功
    const user = {
      id: Math.random().toString(36).substring(2, 10),
      name: username.value,
      email: email.value,
      avatar: '/image/usericon.jpg'
    };

    console.log('注册成功', user);
    showToastMessage('注册成功，正在跳转登录页面...');

    // 延迟跳转，让用户看到提示
    setTimeout(() => {
      navigateTo('/', { replace: true });
    }, 1500);

  } catch (error) {
    console.error('注册失败', error);
    emailError.value = '该邮箱已被注册';
    showToastMessage('注册失败，该邮箱已被注册', 'error');
  } finally {
    isSubmitting.value = false;
  }
};
</script>

<style scoped>
/* 原有样式保持不变 */
/* 页面容器 */
.page-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* 背景装饰 */
.background-decoration {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 10% 20%, rgba(22, 93, 255, 0.15) 0%, rgba(0, 15, 30, 0.9) 100%);
  z-index: -1;
}

/* 内容包装器 */
.content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* 品牌区域 */
.brand-section {
  text-align: center;
  margin-bottom: 3rem;
  color: white;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.logo Icon {
  color: #165DFF;
  filter: drop-shadow(0 0 8px rgba(22, 93, 255, 0.5));
}

.brand-name {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(90deg, #165DFF, #36CFC9);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-tagline {
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.8);
  max-width: 500px;
  line-height: 1.5;
}

/* 认证卡片 */
.auth-card {
  width: 100%;
  max-width: 420px;
  background-color: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 15px 40px rgba(22, 93, 255, 0.2);
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.auth-card:hover {
  transform: translateY(-5px);
}

/* 科技感装饰元素 */
.tech-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, #165DFF, #36CFC9);
}

/* 标题区域 */
.modal-header {
  padding: 35px 30px 20px;
  text-align: center;
  position: relative;
}

.modal-title {
  margin: 0 0 10px 0;
  font-size: 1.6rem;
  color: #0A1629;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.modal-subtitle {
  margin: 0;
  font-size: 0.95rem;
  color: #64748b;
  font-weight: 400;
}

/* 表单样式 */
.auth-form {
  padding: 0 30px 25px;
}

.form-group {
  margin-bottom: 22px;
}

.form-label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.95rem;
  color: #334155;
  font-weight: 500;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

/* 带按钮的输入框 */
.input-wrapper.with-button {
  display: flex;
  gap: 10px;
}

.input-wrapper.with-button .form-input {
  flex: 1;
  padding-right: 15px;
}

.send-code-btn {
  padding: 0 16px;
  background-color: #f0f5ff;
  color: #165DFF;
  border: 1px solid #bed7ff;
  border-radius: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
  height: 52px; /* 与输入框高度一致 */
}

.send-code-btn:hover:not(:disabled) {
  background-color: #e6f0ff;
  border-color: #99c1ff;
}

.send-code-btn:disabled {
  background-color: #f5f7fa;
  color: #c9cdD4;
  border-color: #e5e6eb;
  cursor: not-allowed;
}

.form-input {
  width: 100%;
  padding: 14px 15px 14px 45px;
  border: 1px solid rgba(22, 93, 255, 0.15);
  border-radius: 10px;
  font-size: 1rem;
  transition: all 0.25s ease;
  background-color: rgba(255, 255, 255, 0.7);
  color: #0A1629;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
}

.form-input:focus {
  outline: none;
  border-color: #165DFF;
  box-shadow: 0 0 0 4px rgba(22, 93, 255, 0.1);
  background-color: #fff;
}

.form-input.error {
  border-color: #F53F3F;
}

.form-input.error:focus {
  box-shadow: 0 0 0 4px rgba(245, 63, 63, 0.1);
}

.input-icon {
  position: absolute;
  left: 14px;
  color: #86909C;
  transition: color 0.25s ease;
}

.form-input:focus + .toggle-password Icon,
.form-input:focus ~ .input-icon {
  color: #165DFF;
}

/* 密码切换按钮 */
.toggle-password {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: #86909C;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
}

.toggle-password:hover {
  background-color: rgba(22, 93, 255, 0.05);
  color: #165DFF;
}

/* 密码强度指示器 */
.password-strength {
  margin-top: 10px;
}

.strength-bars {
  display: flex;
  gap: 4px;
  height: 6px;
  margin-bottom: 6px;
}

.strength-bar {
  flex: 1;
  border-radius: 3px;
  transition: all 0.3s ease;
  background-color: #e5e6eb;
}

.strength-bar.empty {
  background-color: #e5e6eb;
}

.strength-bar.weak {
  background-color: #F53F3F;
}

.strength-bar.medium {
  background-color: #FF7D00;
}

.strength-bar.strong {
  background-color: #00B42A;
}

.strength-text {
  font-size: 0.85rem;
  margin-bottom: 4px;
  font-weight: 500;
}

.strength-hint {
  font-size: 0.8rem;
  color: #86909C;
  margin-top: 2px;
  padding-left: 1px;
}

/* 错误信息 */
.error-message {
  margin: 6px 0 0 0;
  font-size: 0.85rem;
  color: #F53F3F;
  min-height: 1.2em;
  display: flex;
  align-items: center;
}

.error-message::before {
  content: "!";
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: #F53F3F;
  color: white;
  font-size: 12px;
  text-align: center;
  line-height: 16px;
  margin-right: 6px;
  font-weight: bold;
}

/* 条款同意区域 */
.terms-agreement {
  margin-bottom: 28px;
}

.terms-label {
  display: flex;
  align-items: flex-start;
  cursor: pointer;
}

.terms-checkbox {
  margin: 3px 8px 0 0;
  width: 16px;
  height: 16px;
  accent-color: #165DFF;
  transition: all 0.2s ease;
}

.terms-checkbox.error {
  outline: 1px solid #F53F3F;
  outline-offset: 2px;
}

.terms-text {
  font-size: 0.85rem;
  color: #64748b;
  line-height: 1.5;
}

/* 链接样式 */
.link {
  color: #86909C;
  font-size: 0.9rem;
  text-decoration: none;
  transition: all 0.25s ease;
  position: relative;
  padding-bottom: 2px;
}

.link:hover {
  color: #165DFF;
}

.link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 1px;
  background-color: #165DFF;
  transition: width 0.25s ease;
}

.link:hover::after {
  width: 100%;
}

.link.primary {
  color: #165DFF;
  font-weight: 500;
}

/* 提交按钮 */
.submit-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(90deg, #165DFF, #0FC6C2);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(22, 93, 255, 0.2);
}

.submit-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: all 0.6s ease;
}

.submit-btn:hover:not(:disabled)::before {
  left: 100%;
}

.submit-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(22, 93, 255, 0.3);
}

.submit-btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 4px 12px rgba(22, 93, 255, 0.2);
}

.submit-btn:disabled {
  background: linear-gradient(90deg, #C9CDD4, #86909C);
  cursor: not-allowed;
  box-shadow: none;
}

.submit-btn Icon[name="material-symbols:how-to-reg"] {
  color: white;
}

/* 加载动画 */
.loading {
  display: flex;
  gap: 8px;
}

.dot {
  width: 9px;
  height: 9px;
  background-color: white;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) {
  animation-delay: -0.32s;
}

.dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* 登录提示 */
.login-prompt {
  text-align: center;
  padding: 0 30px 25px;
  font-size: 0.95rem;
  color: #64748b;
}

/* 谷歌注册区域 */
.google-login-section {
  padding: 0 30px 35px;
}

.divider {
  display: flex;
  align-items: center;
  margin: 25px 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(22, 93, 255, 0.15), transparent);
}

.divider span {
  padding: 0 15px;
  font-size: 0.85rem;
  color: #86909C;
  position: relative;
}

.divider span::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background-color: rgba(22, 93, 255, 0.1);
  z-index: -1;
}

/* 谷歌注册按钮 */
.google-login-btn {
  width: 100%;
  padding: 14px;
  background-color: white;
  color: #333;
  border: 1px solid rgba(22, 93, 255, 0.15);
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  gap: 10px;
}

.google-login-btn:hover {
  background-color: #FAFAFA;
  border-color: rgba(22, 93, 255, 0.25);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.google-login-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

/* 谷歌图标品牌色 */
.google-login-btn Icon[name="fa-brands:google"] {
  background: conic-gradient(
      from -45deg,
      #ea4335 110deg,
      #4285f4 90deg 180deg,
      #34a853 180deg 270deg,
      #fbbc05 270deg
  ) 73% 55%/150% 150% no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  font-size: 1.25rem;
}

/* 页脚 */
.footer {
  margin-top: 3rem;
  text-align: center;
  padding: 0 1rem 2rem;
}

/* 添加Toast通知样式 */
.toast-notification {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 20px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  z-index: 1000;
  transition: transform 0.3s ease, opacity 0.3s ease;
  opacity: 0;
  font-weight: 500;
  min-width: 280px;
  max-width: 90%;
  text-align: center;
}

.toast-notification.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-notification.success {
  background-color: rgba(46, 204, 113, 0.9);
  color: white;
}

.toast-notification.error {
  background-color: rgba(231, 76, 60, 0.9);
  color: white;
}

.toast-icon {
  font-size: 1.2rem;
}

/* 响应式调整 */
@media (max-width: 480px) {
  .auth-card {
    margin: 0 15px;
    border-radius: 12px;
  }

  .modal-header,
  .auth-form,
  .google-login-section,
  .login-prompt {
    padding-left: 20px;
    padding-right: 20px;
  }

  .modal-title {
    font-size: 1.4rem;
  }

  .brand-name {
    font-size: 1.75rem;
  }

  .brand-tagline {
    font-size: 1rem;
    padding: 0 1rem;
  }

  .input-wrapper.with-button {
    flex-direction: column;
    gap: 10px;
  }

  .send-code-btn {
    width: 100%;
    height: auto;
    padding: 12px;
  }
  .yzhm-icon {
    position: absolute;
    top: 23px;
    left: 15px;
    transform: translateY(-50%);
  }
}

/* 动画效果 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand-section, .auth-card, .page-footer {
  animation: fadeIn 0.6s ease forwards;
}

.brand-section { animation-delay: 0.1s; opacity: 0; }
.auth-card { animation-delay: 0.3s; opacity: 0; }
.page-footer { animation-delay: 0.5s; opacity: 0; }
</style>
